﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Battles.Atomics;
using Battles.Controls;

namespace Battles
{
	public partial class MainForm : Form
	{
		private const string NAMESM_FILE = "namesm.txt";
		private const string NAMESW_FILE = "namesw.txt";
		private const string SURNAMES_FILE = "surnames.txt";

		private string[] namesm;
		private string[] namesw;
		private string[] surnames;

		public MainForm()
		{
			InitializeComponent();
			LoadNames();

			army1.OnArmyCreated += ArmyCreatedHandler;
			armyCpu.OnArmyCreated += ArmyCreatedHandler;
		}

		#region - Event handlers. -
		private void BattleBtn_Click(object sender, EventArgs e)
		{
			var a1 = army1.Army;
			var a2 = armyCpu.Army;

			var res = BattleEngine.BattleEngine.Battle(a1, a2);
			army1.Army = a1;
			armyCpu.Army = a2;

			battleRes.Result = res;
		} 

		private void ArmyCreatedHandler (Army army)
		{
			Utils.AssignRandomNames(army.Warriors, namesm, surnames);
		}
		#endregion

		#region - Methods. -
		private void LoadNames ()
		{
			namesm = File.ReadAllLines(NAMESM_FILE);
			namesw = File.ReadAllLines(NAMESW_FILE);
			surnames = File.ReadAllLines(SURNAMES_FILE);
		}
		#endregion
	}
}
